//
//  TrendBottomView.m
//  LiveStar
//
//  Created by 漪珊 on 2017/5/4.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "TrendBottomView.h"
#define kButtonWidth kSCREEN_WIDTH/3

@implementation TrendBottomView
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setUpUI];
    }
    return self;
}

- (UIView *)topSepline {
    if (!_topSepline) {
        _topSepline = [[UIView alloc] init];
        _topSepline.backgroundColor = [UIColor cellLineColor];
    }
    return _topSepline;
}
- (UIButton *)likeBtn {
    if (!_likeBtn) {
        _likeBtn = [[UIButton alloc] init];
        _likeBtn.titleLabel.font = UIFont(10);
        [_likeBtn setImageEdgeInsets:UIEdgeInsetsMake(0, -5, 0, 0)];
        [_likeBtn setTitleColor:HESHEX_COLOR(@"333333") forState:UIControlStateNormal];
        [_likeBtn setImage:kSET_IMAGE(@"praise_normal") forState:UIControlStateNormal];
        [_likeBtn addTarget:self action:@selector(FunctionAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _likeBtn;
}

- (UIButton *)commentBtn {
    if (!_commentBtn) {
        _commentBtn = [[UIButton alloc] init];
        _commentBtn.titleLabel.font = UIFont(10);
        [_commentBtn setImageEdgeInsets:UIEdgeInsetsMake(0, -5, 0, 0)];
        [_commentBtn setTitleColor:HESHEX_COLOR(@"333333") forState:UIControlStateNormal];
        [_commentBtn setImage:kSET_IMAGE(@"comment") forState:UIControlStateNormal];
        [_commentBtn addTarget:self action:@selector(FunctionAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _commentBtn;
}

- (UIButton *)shareBtn {
    if (!_shareBtn) {
        _shareBtn = [[UIButton alloc] init];
        _shareBtn.titleLabel.font = UIFont(10);
        [_shareBtn setImageEdgeInsets:UIEdgeInsetsMake(0, -5, 0, 0)];
        [_shareBtn setTitleColor:HESHEX_COLOR(@"333333") forState:UIControlStateNormal];
        [_shareBtn setImage:kSET_IMAGE(@"share") forState:UIControlStateNormal];
        [_shareBtn addTarget:self action:@selector(FunctionAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _shareBtn;
}

- (void)setUpUI {
    
    //topSeplien
    [self addSubview:self.topSepline];
    [self.topSepline mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self);
        make.left.right.mas_equalTo(self);
        make.height.mas_equalTo(0.5);
    }];
    
    //likeBtn
    [self addSubview:self.likeBtn];
    [self.likeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.mas_equalTo(self);
        make.width.mas_equalTo(kButtonWidth);
    }];
    
    //commentBtn
    [self addSubview:self.commentBtn];
    [self.commentBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.likeBtn.mas_right);
        make.top.bottom.mas_equalTo(self);
        make.width.mas_equalTo(kButtonWidth);
    }];
    
    //shareBtn
    [self addSubview:self.shareBtn];
    [self.shareBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.commentBtn.mas_right);
        make.top.bottom.mas_equalTo(self);
        make.width.mas_equalTo(kButtonWidth);
    }];
}

//toolbar 功能
- (void)FunctionAction:(UIButton *)sender {
    if (sender == self.likeBtn) {//点赞
        [self.delegate ToolBarAction:@"1"];
    } else if (sender == self.commentBtn) {//评论
        [self.delegate ToolBarAction:@"2"];
    } else {//分享
        [self.delegate ToolBarAction:@"3"];
    }
}
@end
